package com.lagou.mr.homework;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

//mr根据key的hashcode进行排序，IntWritable hashcode方法返回的是this.value ，所以将每一行内容放到输出结果的key
public class HomeworkMapper extends Mapper<LongWritable, Text, IntWritable, NullWritable> {

    // k 值
    private IntWritable k = new IntWritable();

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, IntWritable, NullWritable>.Context context) throws IOException, InterruptedException {

        this.k.set(Integer.parseInt(value.toString()));
        context.write(k, NullWritable.get());
    }
}
